package DDE.Dico;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;
import DDE.Dico.Mot;

public class Dico_HashMap {

	private HashMap <String, String> dicoFR;
	private HashMap <String, String> dicoEN;
	
	public Dico_HashMap ()  {
		
		//Recuperation du contenu du fichier dans une arraylist
		File input = new File("./src/DDE/Dico/dico.txt");
		Scanner sc = null;
		try {
			sc = new Scanner(input).useDelimiter("\\s*,\\s*|\r\n");
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		dicoFR = new HashMap<String, String>();
		dicoEN = new HashMap<String, String>();
		while(sc.hasNextLine()) {
	       	Mot mot = new Mot (sc.next(),sc.next());
	       	dicoFR.put(mot.getMotEn(),mot.getMotFr());
	       	dicoEN.put(mot.getMotFr(),mot.getMotEn());
		}
	
	}
	
	public String traduireToFR (String mot){
		String m = "test";
		if (dicoFR.containsKey(mot) == true){
			m = dicoFR.get(mot);
		}
	return m;
	}
	
	public String traduireToEN (String mot){
		String m = null;
		if (dicoEN.containsKey(mot) == true){
			m = dicoEN.get(mot);
		}
	return m;
	}
	
	public int getNbElt() {
		int t = 0;
		int taille = dicoFR.size();
		int taille2 = dicoEN.size();
		if (taille == taille2) {
			t = taille;
		}
		return t;	
	}
	
	public String toStringFR() {
		String t = dicoFR.values().toString();
		return t;
	}
	
	public String toStringEN() {
		String t = dicoEN.values().toString();
		return t;
	}
}
